// JavaScript Document
$(function () {
	initAdd();
	//提交
	$(".submit").on("click",function(){
		checkAdd();
	});
});
//初始化
function initAdd(){
	$(".crmapLongitude").val("");
	$(".crmapLatitude").val("");
	$(".crmapName").val("");
	$(".crmapDesc").val("");
}
//检查提交
function checkAdd(){	
	if($.trim($(".crmapLongitude").val()) == ""){
		alert("经度坐标不能为空，请填写完再提交！");
		$(".crmapLongitude").focus();
		return false;
	}
	if($.trim($(".crmapLatitude").val()) == ""){
		alert("纬度坐标不能为空，请填写完再提交！");
		$(".crmapLatitude").focus();
		return false;
	}
	if($.trim($(".crmapName").val()) == ""){
		alert("标记名称不能为空，请填写完再提交！");
		$(".crmapName").focus();
		return false;
	}
	var r=confirm("是否确认增加？");
	if (r==true){
		var msgObject = parent.layer.msg('处理中，请等待……', {
			icon: 16,
			shade: 0.4,
			time: waitImgTime //（如果不配置，默认是3秒）
		}, function(index){
			//do something
			parent.layer.close(index); 
		});
		Add(msgObject);
	}
}
//提交
function Add(msgObject){
	var crmapLongitude = $(".crmapLongitude").val();
	var crmapLatitude = $(".crmapLatitude").val();
	var crmapName = $(".crmapName").val();
	var crmapDesc = $(".crmapDesc").val();
	var str = 'crmapLongitude='+encodeURIComponent(crmapLongitude)+'&crmapLatitude='+encodeURIComponent(crmapLatitude)+'&crmapName='+encodeURIComponent(crmapName)+'&crmapDesc='+encodeURIComponent(crmapDesc);	
	getOData(str,"coreMap/add/map",{
		fn:function(oData){
			window.parent.refreshList();
			alert("增加成功！");
		},
		fnerr:function(oData){
			parent.layer.close(msgObject);
		}
	});
}